package com.example.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.ExamAntiCheatingRecord;

/**
 * 考试防作弊记录Mapper接口
 * 提供防作弊记录的数据库操作方法
 */
@Mapper
public interface ExamAntiCheatingRecordMapper extends BaseMapper<ExamAntiCheatingRecord> {
    
    /**
     * 根据考试ID查询所有可疑行为记录
     * @param examId 考试ID
     * @return 可疑行为记录列表
     */
    @Select("SELECT * FROM exam_anti_cheating_records WHERE exam_id = #{examId} ORDER BY record_time DESC")
    List<ExamAntiCheatingRecord> findByExamId(@Param("examId") Long examId);
    
    /**
     * 根据考试ID和学生ID查询可疑行为记录
     * @param examId 考试ID
     * @param studentId 学生ID
     * @return 可疑行为记录列表
     */
    @Select("SELECT * FROM exam_anti_cheating_records WHERE exam_id = #{examId} AND student_id = #{studentId} ORDER BY record_time DESC")
    List<ExamAntiCheatingRecord> findByExamIdAndStudentId(@Param("examId") Long examId, @Param("studentId") Long studentId);
    
    /**
     * 根据学生ID查询所有可疑行为记录
     * @param studentId 学生ID
     * @return 可疑行为记录列表
     */
    @Select("SELECT * FROM exam_anti_cheating_records WHERE student_id = #{studentId} ORDER BY record_time DESC")
    List<ExamAntiCheatingRecord> findByStudentId(@Param("studentId") Long studentId);
    
    /**
     * 根据风险等级查询可疑行为记录
     * @param examId 考试ID
     * @param riskLevel 风险等级
     * @return 可疑行为记录列表
     */
    @Select("SELECT * FROM exam_anti_cheating_records WHERE exam_id = #{examId} AND risk_level = #{riskLevel} ORDER BY record_time DESC")
    List<ExamAntiCheatingRecord> findByExamIdAndRiskLevel(@Param("examId") Long examId, @Param("riskLevel") String riskLevel);
    
    /**
     * 统计考试中特定行为类型的总次数
     * @param examId 考试ID
     * @param behaviorType 行为类型
     * @return 总次数
     */
    @Select("SELECT COUNT(*) FROM exam_anti_cheating_records WHERE exam_id = #{examId} AND behavior_type = #{behaviorType}")
    Integer countByExamIdAndBehaviorType(@Param("examId") Long examId, @Param("behaviorType") String behaviorType);
    
    /**
     * 统计学生在特定考试中的可疑行为总次数
     * @param examId 考试ID
     * @param studentId 学生ID
     * @return 总次数
     */
    @Select("SELECT COUNT(*) FROM exam_anti_cheating_records WHERE exam_id = #{examId} AND student_id = #{studentId}")
    Integer countByExamIdAndStudentId(@Param("examId") Long examId, @Param("studentId") Long studentId);
} 